define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');
	
var base=require('component-base');

var history = require('component-history');
	
require('component-page');
	
	  var oldMobile = ""; //手机号码，全局变量
//	 ,,
	/**
	 * 点击安全设置时，初始调用此方法
	 */
exports.init=function(m){
	history.addHis(this,arguments);
	window.$ddf_safe = m;
	  var htmlStr = "";
//		oldMobile = data["oldMobile"];//初始化手机号码
		htmlStr += '<div id="content-header">';
		htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'
				+ ddf.index.index_js
				+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">安全设置</a></div>';
//		htmlStr += '<h1>安全设置</h1>';
		htmlStr += '</div>    ';
		htmlStr += '<div class="container-fluid">';
//		htmlStr += '<hr/>';

		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips0" ></div>';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title">';
		htmlStr += '<span class="icon">';
		htmlStr += '<i class="icon-pencil"></i>';
		htmlStr += '</span>';
		htmlStr += '<h5>操作</h5>';
		htmlStr += '</div>      ';
		htmlStr += '<div class="widget-content">';
		htmlStr += '<div class="div-btn" id="buttonBox">';
		htmlStr += '<button class="btn btn-success" id="editPersonMobileBtn" type="button" onClick=$ddf_safe.editPersonMobile()>更换个人手机号码</button>&nbsp;&nbsp;';
		htmlStr += '<button class="btn btn-success" id="editLoginPwdBtn" type="button" onclick="$ddf_safe.resetLoginPassword()">修改登录密码</button>&nbsp;&nbsp;';
		htmlStr += '<button class="btn btn-warning" id="editmobileBtn" type="button" onclick="$ddf_safe.resetMobile()">更换绑定手机号码</button>&nbsp;&nbsp;';
		htmlStr += '<div id="editPayDiv" style="display:inline">';
		htmlStr += '<button class="btn btn-primary" type="button" style="display:none" id="accountUp" onClick="$ddf_safe.resetPayPassword()">修改支付密码</button>&nbsp;&nbsp;';
		htmlStr += '<button class="btn btn-primary" type="button" style="display:none" id="accountIn" onClick=$ddf_safe.loadinsertPayPassword()>新增支付密码</button>&nbsp;&nbsp;';
		htmlStr += '</div>';
		/*htmlStr += ' <button class="btn btn-success" type="button" onClick=editAgent("'
				+ data["AGENT_ID"]
				+ '","'
				+ data["AGENT_NAME"]
				+ '","'
				+ data["AGENT_TYPE"]
				+ '","'
				+ data["PARENT_AGENT_ID"]
				+ '","'
				+ data["CONTACT"]
				+ '","'
				+ data["CONTACT_NAME"]
				+ '","'
				+ data["MOBILE"] + '","' + data["ADDRESS"] + '","' + data["MEMO"] + '")>修改</button> ';
		htmlStr += ' <button class="btn btn-info" type="button" onClick=back("content2","content0")>返回</button>    ';*/
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>             ';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>安全设置</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<div class="form-horizontal">';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">代理商账号：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="agentName" ></span>'; //+ data["agentName"] +
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">绑定手机号：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id ="oldMobile"></span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">登录密码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span">登录您的商户后台时需要输入的密码</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">支付密码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span">在账户资金变动需要输入的密码</span>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		
		htmlStr += '</div>  ';
		htmlStr += '</div>          ';
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';
		showDiv("content0");
		$("#content0").html(htmlStr);
//		cancelLoading();
	  getSafeDetail(1,pageSize); 
	  getAccount();
	    
  }
  
  /**
   * 获取账户的基本信息
   */
  function getSafeDetail(pageNumber,pageSize){
	  
	  var params = {
				"page.pageNumber" : pageNumber,
				"page.pageSize" : pageSize,
				
			};
	  
	  base.showLoading(); //页面加载
	  eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.queryMessage,params));
			
			getSafeDetailCallBack(data);
			
		}))().start();

  }
  //获取账户的基本信息——回调函数
  function getSafeDetailCallBack(data){
//	  alert("updatePassword="+updatePassword);
	  base.cancelLoading();
	  
	  
	  if(data["CHANGEPERSONMOBILE"]!=true){
		  $("#editPersonMobileBtn").css("display","none");
	  }
	  if(data["CHANGELOGINPWD"]!=true){
		  $("#editLoginPwdBtn").css("display","none");
	  }
	  if(data["CHANGEMOBILE"]!=true){
		  $("#editmobileBtn").css("display","none");
	  }
	  if(data["CHANGEPAYPWD"]!=true){
		  $("#editPayDiv").css("display","none");
	  }
	  
	  if(data["code"] == 1){
		  oldMobile = data["oldMobile"];
		  $("#oldMobile").html(oldMobile);
		  $("#agentName").html(data["agentName"]);
		  
//			var htmlStr = "";
//			oldMobile = data["oldMobile"];//初始化手机号码
//			htmlStr += '<div id="content-header">';
//			htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'
//					+ ddf.index.index_js
//					+ '",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript：void(0)>我的设置</a><a href="javascript:void(0)" class="current">安全设置</a></div>';
////			htmlStr += '<h1>安全设置</h1>';
//			htmlStr += '</div>    ';
//			htmlStr += '<div class="container-fluid">';
////			htmlStr += '<hr/>';
//
//			htmlStr += '<div class="row-fluid">';
//			htmlStr += '<div class="span12">';
//			htmlStr += '<div id="alert-tips0" ></div>';
//			htmlStr += '<div class="widget-box">';
//			htmlStr += '<div class="widget-title">';
//			htmlStr += '<span class="icon">';
//			htmlStr += '<i class="icon-pencil"></i>';
//			htmlStr += '</span>';
//			htmlStr += '<h5>操作</h5>';
//			htmlStr += '</div>      ';
//			htmlStr += '<div class="widget-content">';
//			htmlStr += '<div class="div-btn"><button class="btn btn-warning" type="button" onclick="$ddf_safe.resetMobile()">更换手机号码</button>  <button class="btn btn-success" type="button" onclick="$ddf_safe.resetLoginPassword()">修改登录密码</button> <button class="btn btn-primary" type="button" onClick="$ddf_safe.resetPayPassword()">修改支付密码</button> ';
//			/*htmlStr += ' <button class="btn btn-success" type="button" onClick=editAgent("'
//					+ data["AGENT_ID"]
//					+ '","'
//					+ data["AGENT_NAME"]
//					+ '","'
//					+ data["AGENT_TYPE"]
//					+ '","'
//					+ data["PARENT_AGENT_ID"]
//					+ '","'
//					+ data["CONTACT"]
//					+ '","'
//					+ data["CONTACT_NAME"]
//					+ '","'
//					+ data["MOBILE"] + '","' + data["ADDRESS"] + '","' + data["MEMO"] + '")>修改</button> ';
//			htmlStr += ' <button class="btn btn-info" type="button" onClick=back("content2","content0")>返回</button>    ';*/
//			htmlStr += '</div>';
//			htmlStr += '</div>';
//			htmlStr += '</div>             ';
//			htmlStr += '<div class="widget-box">';
//			htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
//			htmlStr += '<h5>安全设置</h5>';
//			htmlStr += '</div>';
//			htmlStr += '<div class="widget-content nopadding">';
//			htmlStr += '<div class="form-horizontal">';
//			htmlStr += '<div class="control-group">';
//			htmlStr += '<label class="control-label">代理商账号：</label>';
//			htmlStr += '<div class="controls">';
//			htmlStr += '<span class="inp_span">' + data["agentName"] + '</span>';
//			htmlStr += '</div>';
//			htmlStr += '</div>';
//			htmlStr += '<div class="control-group">';
//			htmlStr += '<label class="control-label">绑定手机号：</label>';
//			htmlStr += '<div class="controls">';
//			htmlStr += '<span class="inp_span" id = "oldMobile">' + oldMobile + '</span>';
//			htmlStr += '</div>';
//			htmlStr += '</div>';
//			
//			htmlStr += '<div class="control-group">';
//			htmlStr += '<label class="control-label">登录密码：</label>';
//			htmlStr += '<div class="controls">';
//			htmlStr += '<span class="inp_span">登录您的商户后台时需要输入的密码</span>';
//			htmlStr += '</div>';
//			htmlStr += '</div>';
//			htmlStr += '<div class="control-group">';
//			htmlStr += '<label class="control-label">支付密码：</label>';
//			htmlStr += '<div class="controls">';
//			htmlStr += '<span class="inp_span">在账户资金变动需要输入的密码</span>';
//			htmlStr += '</div>';
//			htmlStr += '</div>';
//			
//			htmlStr += '</div>  ';
//			htmlStr += '</div>          ';
//			htmlStr += '</div>  ';
//			htmlStr += '</div>';
//			htmlStr += '</div> ';
//			htmlStr += '</div> ';
//			$("#content0").css("display", "block");
//			$("#content0").html(htmlStr);
			if(updateMobile){
				base.tips("手机号码修改成功");
			    updateMobile = false;
			}
			if(updatePassword){
				base.tips("登录密码修改成功");
			    updatePassword =false;
			}
			if(updatePayPassword){
				base.tips("支付密码修改成功");
			    updatePayPassword = false;
			}
//			cancelLoading();
		   }else{
			   base.tips_error(data["message"]);
		   }
	  
  }
  
  /**
   * 获取账户信息
   */
  function getAccount(){
  	
  	tips_index=0;

//  	DDF_AsyncRequest("POST",ddf.safeSet.querysafeSet,"",'$ddf_safeSet.getSafeSetCallBack(data)');
  	 eval(Wind.compile("async",function(){
  			
  			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.queryAccount,""));
  			
  			getAccountCallBack(data);
  			
  		}))().start();
  }


  /**
   * 获取账户信息_回调函数
   * @param data
   */
  function getAccountCallBack(data){
  	
  	if(data["code"]==1){
  		if(data["message"] == '-1'){
  			document.getElementById("accountUp").style='display:none';
  			document.getElementById("accountIn").style='display:inline';
  		}else{
  			document.getElementById("accountIn").style='display:none';
  			document.getElementById("accountUp").style='display:inline';
  		}
  	}else{
  		
  		 base.tips_error(data["message"]);
  	}
  	base.cancelLoading();
  	
  }
  
  /**
   * 修改手机号码
   */

  function resetMobile(){
	history.addHis(this,arguments);
	base.showLoading(); //页面加载
    var htmlStr = "";
  	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'
  			+ ddf.index.index_js
  			+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_safe.showDiv("content0")>安全设置</a><a href="javascript:void(0)" class="current">修改手机</a></div></div>';//<h1>安全设置</h1>
  	htmlStr += '<div class="container-fluid">';
//  	htmlStr += '<hr/>';
  	htmlStr += '<div class="row-fluid">';
  	htmlStr += '<div class="span12">';
  	htmlStr += '<div id="alert-tips1" ></div>';
  	htmlStr += '<div class="widget-box">';
  	htmlStr += '<div class="widget-title" id="titleMessage"><span class="icon" ><i class="icon-th"></i>修改手机号码</span></div>  ';
  	htmlStr += '<div class="widget-content nopadding">';
  	htmlStr += '<form class="form-horizontal">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">旧号码：</label><div class="controls" id="updateOldMobile"></div></div></div>';
  	htmlStr += '</div>';

  	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span6"><div class="control-group" id="control-group-mobile-number"><label class="control-label">新号码：</label><div class="controls"><input class="span8 m-wrap" type="text" id="newMobile"/></div></div></div>';
  	htmlStr += '</div>';

  	htmlStr += '<div class="form-actions">';
  	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_safe.saveMessage()">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_safe.showDiv("content0")>返回</button>';
  	htmlStr += '</div>        ';
  	htmlStr += '</form>';
  	htmlStr += '</div>';
  	htmlStr += '</div> ';
  	
  
  	
//  	alert(oldMobile);
  	showDiv("content1");
	$("#content1").html(htmlStr);
	$("#updateOldMobile").html(oldMobile);
//	addErrorMessage("control-group-mobile-number","newMobile","请输入11位数字");  //提示语
	
	$("#newMobile").change(function() {
		newMobile = $("#newMobile").val();
		if(isNull(newMobile)){
			addErrorMessage("control-group-mobile-number","newMobile","手机号码不为空");  //提示语
		}else{
			if(!isMobile(newMobile)){
				addErrorMessage("control-group-mobile-number","newMobile","请输入准确的11位号码");  //提示语
			}else{
				clearErrorMessage("control-group-mobile-number");
			}
		}
	});
	base.cancelLoading(); //取消加载
  }
  
  /**
   * 修改密码
   */
  function resetLoginPassword(){
	  history.addHis(this,arguments);
	  var htmlStr = "";
	  	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'
	  			+ ddf.index.index_js
	  			+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=$ddf_safe.showDiv("content0")>安全设置</a><a href="javascript:void(0)" class="current">修改登录密码</a></div></div>';//<h1>安全设置</h1>
	  	htmlStr += '<div class="container-fluid">';
//	  	htmlStr += '<hr/>';
	  	htmlStr += '<div class="row-fluid">';
	  	htmlStr += '<div class="span12">';
	  	htmlStr += '<div id="alert-tips3" ></div>';
	  	htmlStr += '<div class="widget-box">';
	  	htmlStr += '<div class="widget-title" id="titleMessage"><span class="icon" ><i class="icon-th"></i>修改登录密码</span></div>  ';
	  	htmlStr += '<div class="widget-content nopadding">';
	  	htmlStr += '<form class="form-horizontal">';
	  	
	  	htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group" id="control-group-oldLoginPassword"><label class="control-label">旧密码：</label><div class="controls"><input class="span8 m-wrap" type="password" id="oldLoginPassword"/></div></div></div>';
	  	htmlStr += '</div>';
	  	

	  	htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group" id="control-group-newLoginPassword"><label class="control-label">新密码：</label><div class="controls"><input class="span8 m-wrap" type="password" id="newLoginPassword"/><span class="help-inline">登录密码可由6-20位数字,字母组成</span></div></div></div>';
	  	htmlStr += '</div>';
	  	
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group" id="control-group-confimLoginPassword"><label class="control-label">确认新密码：</label><div class="controls"><input class="span8 m-wrap" type="password" id="confimLoginPassword"/><span class="help-inline">登录密码可由6-20位数字,字母组成</span></div></div></div>';
	  	htmlStr += '</div>';

	  	htmlStr += '<div class="form-actions">';
	  	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_safe.saveLoginPassword()">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;';
		htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_safe.showDiv("content0")>返回</button>';
	  	htmlStr += '</div>        ';
	  	htmlStr += '</form>';
	  	htmlStr += '</div>';
	  	htmlStr += '</div> ';
	  	
	  
	  	
//	  	alert(oldMobile);
	  	showDiv("content2");
		$("#content2").html(htmlStr);
//		addErrorMessage("control-group-mobile-number","newMobile","请输入11位数字");  //提示语
		
		/**
		 * 旧密码的验证
		 */
		$("#oldLoginPassword").change(function() {
			var oldLoginPassword = $("#oldLoginPassword").val();
			if(isNull(oldLoginPassword)){
				addErrorMessage("control-group-oldLoginPassword","oldLoginPassword","旧密码不为空");  //提示语
			}else{
				if(!isLoginPassword(oldLoginPassword)){
					//请输入有字母和数字组成的密码，密码长度为：6-20
				   addErrorMessage("control-group-oldLoginPassword","oldLoginPassword","密码为6-20位数字，字母，符号组合，请重新输入");  //提示语
				}else{
					clearErrorMessage("control-group-oldLoginPassword");
				}
			}
		});
	
		/**
		 * 新密码的验证
		 */
		$("#newLoginPassword").change(function() {
			var oldLoginPassword = $("#newLoginPassword").val();
			
			if(isNull(oldLoginPassword)){
				addErrorMessage("control-group-newLoginPassword","newLoginPassword","新密码不为空");  //提示语
			}else{
				if(!isLoginPassword(oldLoginPassword)){
				   addErrorMessage("control-group-newLoginPassword","newLoginPassword","密码为6-20位数字，字母，符号组合，请重新输入");  //提示语
				}else{
					clearErrorMessage("control-group-newLoginPassword");
				}
			}
		});
		
	   /**
	    * 新密码和确认密码的验证
	    */
		$("#confimLoginPassword").change(function() {
			var confimLoginPassword = $("#confimLoginPassword").val();
			
			if(isNull(confimLoginPassword)){
				addErrorMessage1("control-group-confimLoginPassword","确认密码不为空");  //提示语
			}else{
				if(!isLoginPassword(confimLoginPassword)){
				   addErrorMessage1("control-group-confimLoginPassword","确认密码非法");  //提示语
				}else if(confimLoginPassword != $("#newLoginPassword").val()){
				   addErrorMessage1("control-group-confimLoginPassword","新密码与确认密码不相同");  //提示语
				}else{
					clearErrorMessage("control-group-confimLoginPassword");
				}
			}
		});
		base.cancelLoading(); //取消
  }
  
  /**
   * 修改密码登录密码
   */
  function saveLoginPassword(){
	  var oldLoginPassword = $("#oldLoginPassword").val(); //旧登录密码
	  var newLoginPassword = $("#newLoginPassword").val();
	  var confimLoginPassword = $("#confimLoginPassword").val();
      if(isNull(oldLoginPassword)){
    	  addErrorMessage("control-group-oldLoginPassword","oldLoginPassword","旧密码不为空");  //提示语
          return;
      }else if(isNull(newLoginPassword)){
      	  addErrorMessage("control-group-newLoginPassword","newLoginPassword","新密码不为空");  //提示语
          return;
      }else if(isNull(confimLoginPassword)){
      	  addErrorMessage("control-group-oldLoginPassword","confimLoginPassword","确认密码不为空");  //提示语
      	  return;
      }else if(confimLoginPassword != newLoginPassword){
    	  addErrorMessage1("control-group-newLoginPassword","新密码与确认密码不相同");  //提示语
//    	  tips_error(3, "新密码与确认密码不相同");
    	  return;
      }else if(!isLoginPassword(newLoginPassword)){
    	  addErrorMessage1("control-group-newLoginPassword","密码为6-20位数字，字母，符号组合，请重新输入");  //提示语
      	  return;
      }
      
      var params = {
    	  "oldLoginPwd" : MD5(oldLoginPassword),
    	  "newLoginPwd" : MD5(newLoginPassword)
      };
      eval(Wind.compile("async",function(){
  		
  		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.resetLoginPwd,params));
  		
  		getUpdateLoginPasswordCallBack(data);
  		
  	}))().start();
      
      
  }
  
  var updatePassword = false;
  /**
   * 更新登录密码
   */
  function getUpdateLoginPasswordCallBack(data){
	 
	  if(data["code"] == 1){
			showDiv("content0"); //页面切换
			updatePassword = true;
			eval(Wind.compile("async",function(){
				
				var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.queryMessage,""));
				
				getSafeDetailCallBack(data);
				
			}))().start();
		}else{
			base.tips_error(data["message"]);
		}
  }
  
  /**
   * 修改支付密码
   */
  function resetPayPassword(){
	  history.addHis(this,arguments);
	  var htmlStr = "";
	  	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'
	  			+ ddf.index.index_js
	  			+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=$ddf_safe.showDiv("content0")>我的设置</a><a href="javascript:void(0)" class="current">修改支付密码</a></div></div>'; //<h1>安全设置</h1>
	  	htmlStr += '<div class="container-fluid">';
//	  	htmlStr += '<hr/>';
	  	htmlStr += '<div class="row-fluid">';
	  	htmlStr += '<div class="span12">';
	  	htmlStr += '<div id="alert-tips2" ></div>';
	  	htmlStr += '<div class="widget-box">';
	  	htmlStr += '<div class="widget-title" id="titleMessage"><span class="icon" ><i class="icon-th"></i>修改支付密码</span></div>  ';
	  	htmlStr += '<div class="widget-content nopadding">';
	  	htmlStr += '<form class="form-horizontal">';
	  	
	  	htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group" id="control-group-oldPayPassword"><label class="control-label">旧密码：</label><div class="controls"><input class="span8 m-wrap" type="password" id="oldPayPassword"/></div></div></div>';
	  	htmlStr += '</div>';
	  	

	  	htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group" id="control-group-newPayPassword"><label class="control-label">新密码：</label><div class="controls"><input class="span8 m-wrap" type="password" id="newPayPassword"/><span class="help-inline">支付密码由6位数字组成</span></div></div></div>';
	  	htmlStr += '</div>';
	  	
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group" id="control-group-confimPayPassword"><label class="control-label">确认新密码：</label><div class="controls"><input class="span8 m-wrap" type="password" id="confimPayPassword"/><span class="help-inline">支付密码由6位数字组成</span></div></div></div>';
	  	htmlStr += '</div>';

	  	htmlStr += '<div class="form-actions">';
	  	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_safe.savePayPassword()">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;';
		htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_safe.showDiv("content0")>返回</button>';
	  	htmlStr += '</div>        ';
	  	htmlStr += '</form>';
	  	htmlStr += '</div>';
	  	htmlStr += '</div> ';
	  	
	  
	  	
//	  	alert(oldMobile);
	  	showDiv("content3");
		$("#content3").html(htmlStr);
//		addErrorMessage("control-group-mobile-number","newMobile","请输入11位数字");  //提示语
		
		/**
		 * 旧密码的验证
		 */
		$("#oldPayPassword").change(function() {
			var oldPayPassword = $("#oldPayPassword").val();
			
			if(isNull(oldPayPassword)){
				addErrorMessage("control-group-oldPayPassword","oldPayPassword","旧密码不为空");  //提示语
			}else{
				if(!isPayPassword(oldPayPassword)){
				   addErrorMessage("control-group-oldPayPassword","oldPayPassword","旧支付密码为6为数字，请重新输入。");  //提示语
				}else{
					clearErrorMessage("control-group-oldPayPassword");
				}
			}
		});
	
		/**
		 * 新密码的验证
		 */
		$("#newPayPassword").change(function() {
			var newPayPassword = $("#newPayPassword").val();
			
			if(isNull(newPayPassword)){
				addErrorMessage("control-group-newPayPassword","newPayPassword","新密码不为空");  //提示语
			}else{
				if(!isPayPassword(newPayPassword)){
				   addErrorMessage("control-group-newPayPassword","newPayPassword","新支付密码为6位数字，请重新输入。");  //提示语
				}else{
					clearErrorMessage("control-group-newPayPassword");
				}
			}
		});
		
	   /**
	    * 新密码和确认密码的验证
	    */
		$("#confimPayPassword").change(function() {
			var confimPayPassword = $("#confimPayPassword").val();
			
			if(isNull(confimPayPassword)){
				addErrorMessage1("control-group-confimPayPassword","确认密码不为空");  //提示语
			}else{
				if(!isPayPassword(confimPayPassword)){
				   addErrorMessage1("control-group-confimPayPassword","确认密码非法");  //提示语
				}else if(confimPayPassword != $("#newPayPassword").val()){
				   addErrorMessage1("control-group-confimPayPassword","新支付密码与确认支付密码不相同");  //提示语
				}else{
					clearErrorMessage("control-group-confimPayPassword");
				}
			}
		});
		base.cancelLoading(); //取消
  }
  
   /**
    * 保存支付密码
    */
  function savePayPassword(){
	  var oldPayPassword = $("#oldPayPassword").val();
	  var newPayPassword = $("#newPayPassword").val();
	  var confimPayPassword = $("#confimPayPassword").val();
	  if(isNull(oldPayPassword)){
    	  addErrorMessage("control-group-oldPayPassword","oldPayPassword","旧密码不为空");  //提示语
    	  return;
      }else if(isNull(newPayPassword)){
      	  addErrorMessage("control-group-newPayPassword","newPayPassword","新密码不为空");  //提示语
      	  return;
      }else if(isNull(confimPayPassword)){
      	  addErrorMessage("control-group-oldPayPassword","confimPayPassword","确认密码不为空");  //提示语
      	  return;
      }else if(newPayPassword != confimPayPassword){
    	  addErrorMessage1("control-group-newPayPassword","新密码与确认密码不相同");  //提示语
    	  return;
      }else if(!isPayPassword(newPayPassword)){
    	  addErrorMessage1("control-group-newPayPassword","newPayPassword","新支付密码为6位数字，请重新输入");  //提示语
      	  return;
      }
      var params = {
    	  "oldPayPwd" : MD5(oldPayPassword) ,
    	  "newPayPwd" : MD5(newPayPassword)
      };
      eval(Wind.compile("async",function(){
  		
  		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.resetPayPwd,params));
  		
  		getUpdatePayPasswordCallBack(data);
  		
  	}))().start();

      
  }
  
  
   var updatePayPassword = false;
  /**
   * 修改支付密码的回调函数
   */
  function getUpdatePayPasswordCallBack(data){
//	  alert("修改支付密码的回调函数");
	  if(data["code"] == 1){
		    showDiv("content0"); //页面切换
		    updatePayPassword = true;
			eval(Wind.compile("async",function(){
				
				var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.queryMessage,""));
				
				getSafeDetailCallBack(data);
				
			}))().start();
		}else{
			base.tips_error(data["message"]);
	  }
  }
  
  
  
	
	/**
	 * 保存修改的号码
	 */
	 
	function saveMessage(){
		newMobile = $("#newMobile").val();
		var params = {
				"newMobile" : newMobile
		};
	    if(isNull(newMobile)){
				addErrorMessage("control-group-mobile-number","newMobile","手机号码不为空");  //提示语
				return;
		 }else{
			 if(!isMobile(newMobile)){
					addErrorMessage("control-group-mobile-number","newMobile","手机号码不为非法");  //提示语
					return;
			 }
				clearErrorMessage("control-group-mobile-number");
			}
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.resetMobile,params));
			
			getUpdateMobileCallBack(data);
			
		}))().start();
	}
	
	
	var updateMobile = false;
	/**
	 * 修改手机号码的回调函数
	 */
	function getUpdateMobileCallBack(data){
		if(data["code"] == 1){
			showDiv("content0"); //页面切换
			updateMobile =true;
			eval(Wind.compile("async",function(){
				
				var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.queryMessage,""));
				
				getSafeDetailCallBack(data);
				
			}))().start();
		}else{
			base.tips_error(data["message"]);
		}
	}
	
	/**
	 * 新增支付密码
	 */
	function loadinsertPayPassword(){
		history.addHis(this,arguments);
		var htmlStr="";
		htmlStr += '<div id="content-header">';
		htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_safe.showDiv("content0")>安全设置</a><a href="#" class="current">新增支付密码</a></div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="container-fluid">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		
		htmlStr += '<div id="alert-tips3" ></div>';
		
		
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title">';
		htmlStr += '<span class="icon">';
		htmlStr += '<i class="icon-pencil"></i>';
		htmlStr += '</span>';
		htmlStr += '<h5>操作</h5>';
		htmlStr += '</div>      ';
		htmlStr += '<div class="widget-content">';
		htmlStr += '<input type="button" value="确认新增" class="btn btn-primary" onClick=$ddf_safe.insertPayPassword() /> ';
		htmlStr += '<input type="button" value="返回" class="btn btn-info" onClick=$ddf_safe.showDiv("content0") />';
		htmlStr += '</div>';
		htmlStr += '</div>             ';
		
	    
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>新增支付密码</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">	   ';

		htmlStr += '<div class="control-group" id="control-group-newPayPassword">';
		htmlStr += '<label class="control-label">新密码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span2" type="password" id="input_newPayPassword" value=""/>';
		htmlStr += '</div>              ';
		htmlStr += '</div>';
		
		htmlStr += '<div class="control-group" id="control-group-reNewPayPassword">';
		htmlStr += '<label class="control-label">确认新密码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span2" type="password" id="input_reNewPayPassword" value=""/>';
		htmlStr += '</div>              ';
		htmlStr += '</div>';
		
		htmlStr += '<div class="form-actions">';
//		htmlStr += '<input type="button" value="确认修改" class="btn btn-primary" onClick=updateLoginPassword() /> ';
//		htmlStr += '<input type="button" value="返回" class="btn btn-info" onClick=back("content2","content0") />';
		htmlStr += '</div>';
		
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';
	//	
//		$("#content0").css("display","none");
//		$("#content3").css("display","block");
		showDiv("content3");
		$("#content3").html(htmlStr);
		
		$("#input_newPayPassword").change(function() {

			var newPayPassword=$("#input_newPayPassword").val();
			if(isNull(newPayPassword)){
				addErrorMessage("control-group-newPayPassword","input_newPayPassword","新密码非法");
			}else if(!isPayPassword(newPayPassword)){
				addErrorMessage("control-group-newPayPassword","input_newPayPassword","支付密码为6位数字，请重新输入");
			}else{
				clearErrorMessage("control-group-newPayPassword");
			}

		});

		$("#input_reNewPayPassword").change(function() {

			var newPayPassword=$("#input_newPayPassword").val();
			var reNewPayPassword=$("#input_reNewPayPassword").val();

			if(isNull(reNewPayPassword)){
				addErrorMessage("control-group-reNewPayPassword","input_reNewPayPassword","确认新密码非法");
			}else if(!isPayPassword(reNewPayPassword)){
				addErrorMessage("control-group-reNewPayPassword","input_reNewPayPassword","支付密码为6位数字，请重新输入");
			}else{
				if(newPayPassword==reNewPayPassword){
					clearErrorMessage("control-group-reNewPayPassword");
				}else{
					addErrorMessage("control-group-reNewPayPassword","input_reNewPayPassword","输入的两次新密码不一致");
				}
				
			}

		});
	}


	/**
	 * 新增支付密码
	 */
	function insertPayPassword(){
		var newPayPassword=$("#input_newPayPassword").val();
		var reNewPayPassword=$("#input_reNewPayPassword").val();
		
		if(isNull(newPayPassword)||!isPayPassword(newPayPassword)){
			addErrorMessage("control-group-newPayPassword","input_newPayPassword","新密码非法");
			return;
		}else{
			clearErrorMessage("control-group-newPayPassword");
		}
		
		if(isNull(reNewPayPassword)||!isPayPassword(reNewPayPassword)){
			addErrorMessage("control-group-reNewPayPassword","input_reNewPayPassword","确认新密码非法");
			return;
		}else{
			
			if(newPayPassword==reNewPayPassword){
				clearErrorMessage("control-group-reNewPayPassword");
			}else{
				addErrorMessage("control-group-reNewPayPassword","input_reNewPayPassword","输入的两次新密码不一致");
				return;
			}
			
		}
		
		
		var params={
				"tsAccount.password":MD5(newPayPassword)
		        };
		
		tips_index=3;

		base.showLoading();
		
//		DDF_AsyncRequest("POST",ddf.safeSet.resetPayPwd,params,'$ddf_safeSet.resetPayPwdCallBack(data)');
		 eval(Wind.compile("async",function(){
				
				var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.addUserAccount,params));
				
				insertPayPwdCallBack(data);
				
			}))().start();
	}


	/**
	 * 新增支付密码_回调函数
	 * @param data
	 */
	function insertPayPwdCallBack(data){
		if(data["code"]==1){
			showDiv("content0");
			base.tips(data["message"]);
			getSafeDetail(1,pageSize); 
			getAccount();
		}else if(data["code"]==2){
			base.tips_error(data["message"]);
		}else{
			 base.tips_error(data["message"]);
		}
		base.cancelLoading();
	}
	
	
	

	
	/**
	 * 修改个人手机号码
	 */
	function editPersonMobile(){
		
		history.addHis(this,arguments);
		var htmlStr="";
		 
		htmlStr += '<div id="content-header">';
		htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_safeSet.back("content1","content0")>安全设置</a><a href="#" class="current">修改个人手机</a></div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="container-fluid">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		
		htmlStr += '<div id="alert-tips1" ></div>';
		
		
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title">';
		htmlStr += '<span class="icon">';
		htmlStr += '<i class="icon-pencil"></i>';
		htmlStr += '</span>';
		htmlStr += '<h5>操作</h5>';
		htmlStr += '</div>      ';
		htmlStr += '<div class="widget-content">';
		htmlStr += '<input type="button" value="确认修改" class="btn btn-primary" onClick=$ddf_safe.updatePersonMobile() /> ';
		htmlStr += '<input type="button" value="返回" class="btn btn-info" onClick=$ddf_safe.showDiv("content0") />';
		htmlStr += '</div>';
		htmlStr += '</div>             ';
		
	    
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>修改个人手机</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">	   ';
		htmlStr += '<div class="control-group" id="control-group-oldMobile">';
		htmlStr += '<label class="control-label">旧号码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<span class="inp_span" id="show_old_mobile" ></span>';
		htmlStr += '</div>              ';
		htmlStr += '</div>';
		

		htmlStr += '<div class="control-group" id="control-group-newPersonMobile">';
		htmlStr += '<label class="control-label">新号码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span2" type="text" id="input_personMobile" value=""/>';
		htmlStr += '</div>              ';
		htmlStr += '</div>';
		
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';
		
	    showDiv("content4");	
		$("#content4").html(htmlStr);
		
		
		$("#input_personMobile").change(function() {
			
			var inputMobile=$("#input_personMobile").val();
			
			if(isNull(inputMobile)|| !isMobile(inputMobile)){
				addErrorMessage("control-group-newPersonMobile","input_personMobile","新号码非法");
			}else{
				clearErrorMessage("control-group-newPersonMobile");
			}
			
		});
		
		

		base.showLoading();
		
//		DDF_AsyncRequest("POST",ddf.safeSet.showMobile,"",'$ddf_safeSet.editMobileCallBack(data)');
		 eval(Wind.compile("async",function(){
				
				var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.showPersonMobile,""));
				
				editPersonMobileCallBack(data);
				
			}))().start();
	}

	//显示商家手机号码
	function editPersonMobileCallBack(data){
		if(data["code"]==1){
			$("#show_old_mobile").html(data["oldMobile"]);
		}else{
			
			 base.tips_error(data["message"]);
		}
		base.cancelLoading();
		
	}


	/**
	 * 重置商家手机号码
	 */
	function updatePersonMobile(){
		
		var newMobile=$("#input_personMobile").val();
		
		if(isNull(newMobile)||!isMobile(newMobile)){
			addErrorMessage("control-group-newPersonMobile","input_personMobile","新电话号码非法");
			return;
		}
		
		
		var params={
				"newMobile":newMobile
		        };
		
		tips_index=1;

		base.showLoading();
		
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.safe.resetPersonMobile,params));
			
			resetPersonMobileCallBack(data);
			
		}))().start();
		
	}

	/**
	 * 重置商家手机号码_回调函数
	 */
	function resetPersonMobileCallBack(data){
		if(data["code"]==1){
			showDiv("content0");
			base.tips(data["message"]);
			getSafeSet();
		}else{
			
			 base.tips_error(data["message"]);
		}
		base.cancelLoading();
	}

	/**
	 * 显示DIV
	 */
	function showDiv(block){
		
		$("#content > div").hide();
		
		if($("#"+block).length<=0){
			
			$("#content").append('<div id="'+block+'"></div>'); 
			
		}else{
			
			$("#"+block).show();
		}
		
		if(block=="content0"){
			shopTypeId="";
		}
		

		
	}
	
	exports.getAccount=getAccount;
	exports.getAccountCallBack=getAccountCallBack;
  exports.resetMobile = resetMobile; //修改手机号码
  exports.resetLoginPassword = resetLoginPassword; //修改登录密码
  exports.saveLoginPassword = saveLoginPassword; //修改登录密码
  exports.savePayPassword = savePayPassword; //保存修改支付密码
  exports.showDiv = showDiv; 
  exports.resetPayPassword = resetPayPassword; //修改支付密码
  exports.saveMessage = saveMessage; //保存手机号码
  exports.loadinsertPayPassword=loadinsertPayPassword;
  exports.insertPayPassword=insertPayPassword;
  exports.insertPayPwdCallBack=insertPayPwdCallBack;
  exports.editPersonMobile=editPersonMobile;
  exports.updatePersonMobile=updatePersonMobile;
});